import type { Article, ArticleListItem, CreateArticleDTO, UpdateArticleDTO } from '@/types/article'
import request from '@/utils/request'

// 文章查询参数接口
export interface ArticleQueryParams {
  page: number
  page_size: number
}

// 获取文章列表
export function getArticleList(params: ArticleQueryParams = { page: 1, page_size: 10 }) {
  return request({
    url: '/articles/getAllArticles',
    method: 'get',
    params,
  })
}

// 获取已发布的文章列表
export function getPublishedArticles(params: ArticleQueryParams = { page: 1, page_size: 10 }) {
  return request({
    url: '/articles/getPublishedArticles',
    method: 'get',
    params,
  })
}

// 获取单个文章
export function getArticle(id: string) {
  return request({
    url: `/articles/getArticleById/${id}`,
    method: 'get',
  })
}

// 创建文章
export function createArticle(data: CreateArticleDTO) {
  return request({
    url: '/articles/createArticle',
    method: 'post',
    data,
  })
}

// 更新文章
export function updateArticle(id: string, data: UpdateArticleDTO) {
  return request({
    url: `/articles/updateArticle/${id}`,
    method: 'put',
    data,
  })
}

// 删除文章
export function deleteArticle(id: string) {
  return request({
    url: `/articles/deleteArticle/${id}`,
    method: 'delete',
  })
}




